package com.sskj.mine.ui.activity;


import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.bulong.rudeness.RudenessScreenHelper;
import com.shizhefei.mvc.MVCCoolHelper;
import com.shizhefei.view.coolrefreshview.CoolRefreshView;
import com.sskj.common.adapter.slimadapter.IViewInjector;
import com.sskj.common.adapter.slimadapter.SlimAdapter;
import com.sskj.common.adapter.slimadapter.SlimInjector;
import com.sskj.common.base.App;
import com.sskj.common.box.decoration.DividerLineItemDecoration;
import com.sskj.lib.RConfig;
import com.sskj.lib.base.BaseActivity;
import com.sskj.lib.mvchelper.ModelRx2DataSource;
import com.sskj.lib.util.CommonUtil;
import com.sskj.lib.util.HideUtil;
import com.sskj.mine.R;
import com.sskj.mine.R2;
import com.sskj.mine.bean.DetailListBean;
import com.sskj.mine.presenter.DetailListActivityPresenter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

@Route(path = RConfig.MINE_DETAIL_LIST)//佣金明细
public class DetailListActivity extends BaseActivity<DetailListActivityPresenter> {
    @BindView(R2.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R2.id.coolRefreshView)
    CoolRefreshView coolRefreshView;

    @Override
    protected int getLayoutId() {
        return R.layout.mine_activity_detail_list;
    }

    @Override
    public DetailListActivityPresenter getPresenter() {
        return new DetailListActivityPresenter();
    }

    @Override
    protected void initView() {
        setTitle(App.INSTANCE.getString(R.string.mine_detailListActivity1_j));
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.addItemDecoration(new DividerLineItemDecoration(this)
                .setPaintWidth((int) RudenessScreenHelper.pt2px(App.INSTANCE, 20))
                .setDividerColor(ContextCompat.getColor(App.INSTANCE, R.color.transparent))
        );
        SlimAdapter slimAdapter = SlimAdapter.create().register(R.layout.mine_recy_item_detail_list, new SlimInjector<DetailListBean>() {
            @Override
            public void onInject(DetailListBean data, IViewInjector injector, List payloads) {
                injector
                        .text(R.id.tvPhone, HideUtil.getPhoneHide(data.getRealname()))
                        .text(R.id.tvTime, data.getAddtime())
                        .text(R.id.tvMoney, CommonUtil.dealPlus(data.getPrice()));

            }
        }).attachTo(recyclerView).updateData(new ArrayList());
        ModelRx2DataSource<DetailListBean> dataSource = new ModelRx2DataSource<>((ModelRx2DataSource.OnLoadSource<DetailListBean>)
                page -> mPresenter.getData(page + "", "20"), 20);
        MVCCoolHelper<List<DetailListBean>> mvcHelper = new MVCCoolHelper<>(coolRefreshView);
        mvcHelper.setDataSource(dataSource);
        mvcHelper.setAdapter(slimAdapter);
        mvcHelper.refresh();
    }

}
